//
//  UIBarButtonItem+Extension.swift
//  ZZY微博
//
//  Created by 庄壮勇 on 2018/1/12.
//  Copyright © 2018年 Personal. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
    /// 创建 UIBarButtonItem
    ///
    /// - Parameters:
    ///   - title: title
    ///   - fontSize: fontSize， 默认 16号
    ///   - target: target
    ///   - action: action
    ///   - isBack: 是否是返回按钮，如果是加上箭头
    convenience  init(title: String, fontSize: CGFloat = 16, target: Any?, action: Selector, isBack: Bool = false) {

        let btn = UIButton(title: title, fontSize: fontSize, color: UIColor.darkGray, heighlightedColor: UIColor.orange)
        if isBack {
            let imageName = "navigationbar_back_withtext"
            btn.setImage(UIImage(named: imageName), for: .normal);
            btn.setImage(UIImage(named: imageName + "_highlighted"), for: .highlighted);
            btn.sizeToFit()
        }
        btn.addTarget(target, action: action, for: .touchUpInside)
        
        // self.init实例化 UIBarButtonItem
        self.init(customView: btn)
        
    }
}
